﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Licensed under the MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once

#include "GalleryDefinition.h"
#include "ControlDefinition.h"
#include "IGalleryEvent.h"
#include "WeakPtr.h"

namespace gcmp
{
    class ControlDefinitionChangeEvent;
    class IControlDefinitionChangeEvent;
    class GalleryItemDefinition;
    class GCMP_GUI_BASE_IMPL_EXPORT GalleryDefinitionReference : public IGalleryDefinition
    {
        CANNOT_COPY_OR_ASSIGN(GalleryDefinitionReference);
    public:
        GalleryDefinitionReference(GalleryDefinition* pGalleryDefinition);
        virtual ~GalleryDefinitionReference();

        virtual int GetItemWidth() const override;
        virtual int GetItemHeight() const override;

        virtual bool SetCurrentGalleryItem(const std::wstring& id) override;

        void SetCurrentIndex(int index);
        virtual int GetCurrentIndex() const override;

        virtual bool SetColumnCount(int columnCount) override;
        virtual int GetColumnCount() const override;

        virtual const IGalleryItemDefinition* GetCurrentItem() const override;
        virtual IGalleryItemDefinition* GetItem(int index) const override;

        virtual std::vector<IGalleryItemDefinition*> GetAllItems() const override;
        virtual bool AddItem(const std::wstring& id, const std::wstring& caption, const std::wstring& tooltip, const std::wstring& iconPath, const Any& userData) override;

        virtual IGalleryItemDefinition* GetItem(const std::wstring& id) const override;
        virtual int GetItemIndex(const std::wstring& id) const override;

        virtual bool InsertItem(const std::wstring& beforeId, const std::wstring& id, const std::wstring& caption, const std::wstring& tooltip, const std::wstring& iconPath, const Any& userData) override;

        virtual bool DeleteItem(const std::wstring& id) override;

        virtual bool DeleteAllItems() override;

        virtual IGalleryEvent* GetEvent() const override;
        virtual ControlDefinitionType GetType() const override { return ControlDefinitionType::Gallery; }

        IControlDefinitionChangeEvent* GetControlDefinitionChangeEvent() const;

        virtual std::wstring GetId() const override;
        virtual std::wstring GetCaption() const override;
        virtual std::wstring GetTooltip() const override;
        virtual bool IsVisible() const override;
        virtual bool IsEnabled() const override;
    private:
        WeakPtr<GalleryDefinition> m_wpGalleryDefinition;
    };
}

